package com.zzz.demo.async;

import com.zzz.demo.interf.AsyncTaskListener;
import com.zzz.demo.interf.impl.AsyncTaskAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author ZZZ
 * @version 1.0
 * @desc 异步处理数据导入校验
 * @date 2018/7/05 0005
 */
@Component
@EnableAsync
class AsynchronDealDataCheckImpl implements IAsynchronDealDataCheck {

    /**
     * Logger for this class
     */
    private static final Logger logger = LoggerFactory.getLogger(AsyncTaskAdapter.class);

    private AsyncTaskListener asyncTaskListener = null;

    public void setAsyncTaskListener(AsyncTaskListener asyncTaskListener) {
        this.asyncTaskListener = asyncTaskListener;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    @Async
    public void handleCheck()  {
        //开始任务
        asyncTaskListener.onStart();
        try {
            System.out.println("开始执行了："+ UUID.randomUUID());
            //执行完毕
            asyncTaskListener.onSuccess();
        } catch (Exception e) {
            //执行失败
            asyncTaskListener.onFailed();
        }
    }
}